package com.globalwave.common.service;


import com.globalwave.base.BaseServiceImpl;
import com.globalwave.common.ArrayOrderList;
import com.globalwave.common.ArrayPageList;
import com.globalwave.common.entity.SyncControl;

public class SyncControlServiceImpl 
       extends BaseServiceImpl 
       implements SyncControlService {

	
 
    
    public SyncControl create(SyncControl SyncControl) throws Exception {
    	
    	final SyncControl result = (SyncControl) jdbcDao.insert(SyncControl);
    	
    	return result ;
    }

    public void update(SyncControl SyncControl) throws Exception {
        jdbcDao.update(SyncControl) ;
    }

    public void delete(SyncControl SyncControl) throws Exception {
        
        jdbcDao.delete(SyncControl) ;
        
    }


    public ArrayPageList<SyncControl> query(
    		SyncControl SyncControlCriterion, 
            int pageIndex, 
            int pageSize, 
            ArrayOrderList orderList) throws Exception {
        /*
        if (orderList == null) {
            orderList = new ArrayOrderList() ;
            orderList.addAsc("index_") ;
        }*/
        
        return (ArrayPageList<SyncControl>)jdbcDao.query(SyncControlCriterion, pageIndex, pageSize, orderList, SyncControl.class);
    }

	@Override
	public SyncControl findByCodeAndTable(String sourceDbCode, String syncConfigCode) throws Exception {
        
		SyncControl syncControlCriterion = new SyncControl();
		syncControlCriterion.setSourceDbCode(sourceDbCode) ;
		syncControlCriterion.setSyncConfigCode(syncConfigCode) ;
		
    	//SyncControlCriterion.setSyncControlId(SyncControlId) ;
    	ArrayPageList<SyncControl> SyncControls = query(syncControlCriterion, -1, 1, null) ;
    	if (SyncControls.size() > 0) {
    		return SyncControls.get(0) ;
    	}
		return null;
	}
}
